package com.fgsort;

import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTabbedPane;
import javax.swing.JToolBar;

public class MainFrame extends JFrame {
	private static final long serialVersionUID = 1L;
	
	public MainFrame(String title) {
		super(title);
		
		// Creates a menubar for a JFrame
        JMenuBar menuBar = new JMenuBar();
        
        // Add the menubar to the frame
        setJMenuBar(menuBar);
        
        // Define and add two drop down menu to the menubar
        JMenu fileMenu = new JMenu("File");
        JMenu editMenu = new JMenu("Edit");
        menuBar.add(fileMenu);
        menuBar.add(editMenu);
		
        // Create and add simple menu item to one of the drop down menu
        JMenuItem newAction = new JMenuItem("New");
        JMenuItem openAction = new JMenuItem("Open");
        JMenuItem exitAction = new JMenuItem("Exit");
       
        fileMenu.add(newAction);
        fileMenu.add(openAction);
        fileMenu.add(exitAction);
        
        JToolBar toolbar = new JToolBar();

        ImageIcon xmlicon = new ImageIcon(getClass().getResource("xml-icon.png"));
        ImageIcon jsicon = new ImageIcon(getClass().getResource("js-icon.png"));

        JButton btnXmlOpen = new JButton(xmlicon);
        btnXmlOpen.setToolTipText("open xml file for editing");
        JButton btnJsOpen= new JButton(jsicon);
        btnJsOpen.setToolTipText("does nothing for now");
        
        toolbar.add(btnXmlOpen);
        toolbar.add(btnJsOpen);
        
		///set layout manager
		getContentPane().setLayout(new BorderLayout());

		///create options panel on lhs
		final OptionPanel optionPanel = new OptionPanel();
		
		///create output window on rhs
		final OutputPanel outputPanel = new OutputPanel("Function Groups Sorted");
		
		///get email contact text from DetailsPanel
		optionPanel.addOptionListener(new OptionListener() {
            public void detailEventOccurred(OptionEvent event) {
                String funcGrp = event.getText();

                outputPanel.setDisplayOutput(funcGrp);
            }
        });
			
		// add swing components to content pane
		Container c = getContentPane();
		
		final JTabbedPane tab = new JTabbedPane();
		c.add(tab, BorderLayout.CENTER);
		c.add(toolbar, BorderLayout.NORTH);
		tab.add("FgSort", optionPanel);
		tab.add("Debug", outputPanel);
		//tab.add(optionPanel, BorderLayout.WEST);
		//tab.add(outputPanel, BorderLayout.CENTER);
		//tab.remove(component)
		
        btnXmlOpen.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent event) {
                
            	//tab.add("xml", new JPanel());
            	//tab.removeTabAt("xml");
            	//tab.getName();
            }
        });

		
        newAction.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
            	JOptionPane.showMessageDialog(MainFrame.this,"new file was pressed","Information",JOptionPane.ERROR_MESSAGE);
            }
        });

        exitAction.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
        		System.exit(0);
            }
        });

	}
}
